<html>
<head><meta charset="utf-8"><title>Spans on same line · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Spans.20on.20same.20line.html">Spans on same line</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="241632151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Spans%20on%20same%20line/near/241632151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bastian <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Spans.20on.20same.20line.html#241632151">(Jun 05 2021 at 11:43)</a>:</h4>
<p>Hei there <span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> I have a question concerning a lint. I would like to check if two Spans are on the same line of code. I found a bit of a hacky way to do it by using <code>clippy_utils::line_span</code>, which gives me the span until the beginning of the line. I expand both spans this way and then compare boths <code>span.lo()</code> positions to check if both spans begin on the same position. Do maybe someone know if there's a nicer way to do it? And if not, should I add a utility method to clippy_utils/lib.rs?</p>



<a name="241742515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Spans%20on%20same%20line/near/241742515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Spans.20on.20same.20line.html#241742515">(Jun 07 2021 at 08:13)</a>:</h4>
<p>I guess, you're talking about <a href="https://github.com/rust-lang/rust-clippy/issues/7326">rust-clippy#7326</a>? I still have to review that PR.</p>
<p>I think you can just get the line with <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html#method.lookup_line"><code>SourceMap::lookup_line</code></a> and then compare source file and line of the two spans.</p>



<a name="241775687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Spans%20on%20same%20line/near/241775687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Spans.20on.20same.20line.html#241775687">(Jun 07 2021 at 13:27)</a>:</h4>
<p>Another way is to join the spans and use <code>SourceMap::is_multiline</code>: <code>source_map().is_multiline(a.to(b))</code></p>



<a name="241791620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Spans%20on%20same%20line/near/241791620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bastian <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Spans.20on.20same.20line.html#241791620">(Jun 07 2021 at 15:12)</a>:</h4>
<p>Ah great thank you a lot! I will adapt the changes in PR <a href="https://github.com/rust-lang/rust-clippy/issues/7326">rust-clippy#7326</a> before you review <span class="user-mention" data-user-id="264664">@flip1995</span>!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>